package com.util.sql;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Proxy;
import java.util.Properties;

/**
 * 读取工厂配置方法
 */
public class SqlConfigFactory {
    public SqlConfigFactory(){

    }

    /**
     * 读取方法
     * @param inputStream
     * @return
     */
    public static SqlConfigService readProperties(final InputStream inputStream){
        final Properties properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            System.out.println("加载配置文件错误");
            return  null;
        }
        //java代理机制
        return  (SqlConfigService) Proxy
                .newProxyInstance(SqlConfigService.class.getClassLoader()
                ,new Class[]{SqlConfigService.class}
                ,new PropertyInvocationHacdle(properties));
    }
}

